import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

let systemInfo = uni.getSystemInfoSync();
let capsuleInfo;

// #ifdef MP-WEIXIN
capsuleInfo = uni.getMenuButtonBoundingClientRect();
// #endif

// #ifdef H5
capsuleInfo = {
  bottom: 80,
  height: 50,
  left: 281,
  right: 368,
  top: 0,
  width: 100,
}
// #endif

let capsuleToStatusBarPx = capsuleInfo.top - systemInfo.statusBarHeight; //胶囊和状态栏之间的高度
let navbarBodyHeightPx = capsuleInfo.height + (capsuleToStatusBarPx * 2); //标题栏内容高度
let navbarBodyWidthPx = systemInfo.screenWidth - ((systemInfo.windowWidth - capsuleInfo.right) * 2 + capsuleInfo.width); //胶囊实际占用的宽度 px
/**
 * 底部安全距离高度（iphoneX） 单位 px
 */
let safetyBottomHeightPx = systemInfo.screenHeight - systemInfo.safeArea.bottom;
systemInfo.safeArea.safetyBottomHeightPx = safetyBottomHeightPx;


const store = new Vuex.Store({
	state: {
		window: {
		  system: systemInfo,
		  capsule: capsuleInfo,
		  capsuleToStatusBarPx,
		  capsuleInfo,
		  safetyBottomHeightPx,
		  navbar: {
		    bodyHeightPx: navbarBodyHeightPx,
		    bodyWidthPx: navbarBodyWidthPx,
		  },
		  pageHeightRpx: (750 / systemInfo.windowWidth) * systemInfo.windowHeight,
		},
		hasLogin: false,
		userInfo: {},
		appInfo : {}
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider  
			}); 	
			// uni.setStorageSync('token', provider.token);	
		},
		app_info(state,provider){
			 state.appInfo = provider;
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
			    key: 'userInfo'  
			})
			uni.removeStorage({
			    key: 'token'  
			})		
		}
	},
	actions: {
	    set_app_info({commit}, info){
			// console.log(2222)
			 commit('app_info',info);
		}
	}
})
export default store
